from interface.member import MemberInterface
from utils.send_method import SendMethod

from pprint import pprint


class OrderInterface:
    def __init__(self, headers):
        self.url = 'http://47.108.206.100:8085'
        self.headers = headers

    def confirm_order(self, cart_id):
        # 确认订单
        method = 'post'
        url = self.url + '/order/generateConfirmOrder'
        payload = [cart_id]
        return SendMethod.send_method(method=method, url=url, json=payload, headers=self.headers)

    # 生成订单
    def generate_order(self,cart_id):
        url = self.url + "/order/generateOrder"
        payload = {
            "cartIds": [cart_id],
            "memberReceiveAddressId": 715123,
            "payType": 1,
        }
        return SendMethod.send_method(method='post', url=url, json=payload, headers=self.headers)

    def pay_success(self, orderid):
        url = self.url + "/order/paySuccess"
        return SendMethod.send_method(method='post', url=url, data=orderid, headers=self.headers)


if __name__ == '__main__':
    body = {
        "username": "liyimei",
        "password": "123456"
    }
    orderid = {
        "orderId": 9675,
        "payType": 1
    }
    headers = MemberInterface().get_token(body)
    order = OrderInterface(headers)
    # pprint(order.confirm_order(9065))  # 调用确认订单接口
    # pprint(order.generate_order(9065))  # 调用生成订单接口
    pprint(order.pay_success(orderid))  # 调用支付成功回调接口
